package com.cskaoyan.market.service.impl;


import com.cskaoyan.market.db.domain.MarketAdmin;
import com.cskaoyan.market.db.domain.MarketAdminExample;
import com.cskaoyan.market.db.domain.MarketCategoryExample;
import com.cskaoyan.market.db.mapper.MarketAdminMapper;
import com.cskaoyan.market.service.AdminAdminService;
import com.cskaoyan.market.util.MybatisUtils;
import com.github.pagehelper.PageHelper;
import org.apache.ibatis.session.SqlSession;

import java.util.List;
import java.util.Map;

public class AdminAdminServiceImpl implements AdminAdminService {

    @Override
    public List<MarketAdmin> list(int page, int limit, String sort, String order) {
        SqlSession session = MybatisUtils.getSession();
        MarketAdminMapper mapper = session.getMapper(MarketAdminMapper.class);
        MarketAdminExample marketadminExample=new MarketAdminExample();
        marketadminExample.setOrderByClause(sort +" "+order);
        PageHelper.startPage(page, limit);
        List<MarketAdmin> marketadmins = mapper.selectByExample(marketadminExample);
        session.close();
        return marketadmins;
    }

    @Override
    public int update(MarketAdmin marketAdmin) {
        MarketAdminExample marketadminExample = new MarketAdminExample();
        marketadminExample.createCriteria().andIdEqualTo(marketAdmin.getId());
        return MybatisUtils.getSession(true).getMapper(MarketAdminMapper.class).updateByExampleSelective(marketAdmin,marketadminExample);
    }

    @Override
    public int create(MarketAdmin marketAdmin) {
        return MybatisUtils.getSession(true).getMapper(MarketAdminMapper.class).insertSelective(marketAdmin);
    }

    @Override
    public int delete(MarketAdmin marketAdmin) {
        return MybatisUtils.getSession(true).getMapper(MarketAdminMapper.class).deleteByPrimaryKey(marketAdmin.getId());
    }
}
